home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / TERM_VLA.ZIP / TERM1.ASM < prev    next >
Assembly Source File  |  1993-08-27  |  9KB  |  399 lines

  1.     IDEAL
  2.     DOSSEG
  3.     MODEL SMALL
  4.     STACK 400h
  5.     CODESEG
  6.     p286
  7. ────────────────────────────────────────────────────────────────────────────
  8. TimeOut     =   364                 ;20 seconds (18.2 * 20)
  9. NormWait    =   18                  ;1 second
  10. BuffSize    =   2048                ;Size of incoming buffer (in bytes)
  11.  
  12. ; The following equates are modem configuration settings
  13. ComInt      =   0ch     ;COM1/COM3=0Ch, COM2/COM4=0Bh
  14. ComAddr     =   3F8h    ;COM1=3F8h, COM2=2F8h, COM3=3E8h, COM4=2E8h
  15.  
  16. BRDMSB      =   0
  17. BRDLSB      =   03h
  18.  
  19. ;BRDMSB = 0 
  20. ;BRDLSB = 1,843,200/(16*baud rate)              
  21. ;
  22. ; 60h = 1200
  23. ; 30h = 2400
  24. ; 0ch = 9600
  25. ; 06h = 19200
  26. ; 03h = 38400
  27. ; 02h = 57600
  28. ; 01h = 115200
  29.  
  30. ; The following equates are for data format settings
  31. DF_N81      =       00000011b           ;8 data bits, 1 stop bit, no parity
  32. DF_E71      =       00011010b           ;7 data bits, 1 stop bit, even parity
  33.  
  34. OldComInt   dd      ?
  35.  
  36. SendCount   dw      0000
  37. CTMax       DW      0000
  38.  
  39. MSG_SetUp   db      'Setting up modem information ...',13,10,0
  40. MSG_NoMem   db      'Could not allocate buffer space',13,10,0
  41. MSG_Exit    db      'Press F-12 to exit program',13,10,13,10,0
  42. MSG_TimeOut db      '!',0
  43.  
  44. BuffSeg     DW      0000
  45. Head        DW      0000
  46. Tail        DW      0000
  47.  
  48. LocalEcho   db  0
  49. ────────────────────────────────────────────────────────────────────────────
  50.     ────────────────────────────────────────────────────────────────────
  51.     ; The following routine hooks in the interrupt routine and sets up 
  52.     ;the data format and communications parameters
  53.     ────────────────────────────────────────────────────────────────────
  54. PROC SetUpComPort NEAR
  55.     pusha
  56.     push    ds es
  57.     mov     ax,cs
  58.     mov     ds,ax
  59.  
  60.     mov     si,offset MSG_SetUp
  61.     call    PrintZ
  62.  
  63.     mov     al,ComInt
  64.     mov     ah,35h
  65.     int     21h
  66.     mov     [WORD LOW  OldComInt],bx
  67.     mov     [WORD HIGH OldComInt],es
  68.  
  69.     mov     al,ComInt
  70.     mov     dx,offset IntHandler    ;ds:dx = new int vector
  71.     mov     ah,25h
  72.     int     21h
  73.  
  74.     cli
  75.     mov     dx,ComAddr+3            ;point to Line Control register
  76.     mov     al,DF_N81
  77.     out     dx,al
  78.     inc     dx                      ;point to modem control register
  79.     mov     al,00001011b            ;set it for interrupts
  80.     out     dx,al
  81.  
  82.     in      al,21h
  83.     and     al,11100111b            ;enable both IRQ's
  84.     out     21h,al
  85.  
  86.     mov     dx,ComAddr+1
  87.     mov     al,00000001b            ;turn on int's
  88.     out     dx,al
  89.     sti
  90.  
  91.     call    SetBaudRate
  92.  
  93.     pop     es ds
  94.     popa
  95.     ret
  96. ENDP
  97.     
  98.     ────────────────────────────────────────────────────────────────────
  99.     ; This one disables the com port and turns off the interrupt
  100.     ────────────────────────────────────────────────────────────────────
  101. PROC TurnOffComPort NEAR
  102.     pusha
  103.  
  104.     mov     dx,ComAddr+1
  105.     mov     al,0            ;disable interrupts
  106.     out     dx,al
  107.  
  108.     in      al,21h
  109.     or      al,00011000b    ;disable com interrupts
  110.     out     21h,al
  111.  
  112.     push    ds
  113.     mov     dx,[WORD LOW  OldComInt]
  114.     mov     ds,[WORD HIGH OldComInt]
  115.     mov     al,ComInt
  116.     mov     ah,25h
  117.     int     21h
  118.     pop     ds
  119.  
  120.     popa
  121.     ret
  122. ENDP
  123.     ────────────────────────────────────────────────────────────────────
  124.     ; Checks the input buffer and displays everything there
  125.     ────────────────────────────────────────────────────────────────────
  126. PROC DisplayBuffer NEAR
  127.     pusha
  128.     push    es
  129.  
  130.     mov     si,[cs:Tail]
  131.     cmp     si,[cs:Head]
  132.     je      @@NoInput
  133.  
  134.     mov     es,[cs:BuffSeg]
  135.     cld
  136. @@PrintLoop:
  137.     mov     dl,[es:si]
  138.     inc     si
  139.     mov     ah,2
  140.     int     21h
  141.     cmp     si,BuffSize
  142.     jne     @@NotAtEnd
  143.     xor     si,si
  144.  
  145. @@NotAtEnd:
  146.     cmp     si,[cs:Head]
  147.     jne     @@PrintLoop
  148.     mov     [cs:Tail],si
  149.  
  150. @@NoInput:
  151.     pop     es
  152.     popa
  153.     ret
  154. ENDP
  155.     ────────────────────────────────────────────────────────────────────
  156.     ; Sends a character across the serial line 
  157.     ;
  158.     ; IN: AL = Char
  159.     ;OUT: CF = 1 if timeout occurred
  160.     ────────────────────────────────────────────────────────────────────
  161. PROC SendChar NEAR
  162.     pusha
  163.     push    ax
  164.     xor     ah,ah
  165.     int     1ah
  166.     mov     [cs:SendCount],dx
  167.  
  168. @@Xloop1:
  169.     mov     dx,ComAddr+5
  170.     in      al,dx
  171.     test    al,00100000b        ;we ready to send?
  172.     jnz     @@XLoop2
  173.  
  174.     mov     bx,[cs:SendCount]
  175.     mov     ax,NormWait
  176.     call    CheckTime
  177.     jnc     @@XLoop1
  178.     pop     ax
  179.     jmp     short @@XBad
  180.  
  181. @@XLoop2:
  182.     pop     ax
  183.     mov     dx,ComAddr
  184.     out     dx,al
  185.  
  186.     clc
  187.     jmp     short @@Exit
  188.  
  189. @@XBad:
  190.     stc
  191. @@Exit:
  192.     popa
  193.     ret
  194. ENDP
  195.     ────────────────────────────────────────────────────────────────────
  196.     ; Routine to check if time has elapsed
  197.     ;
  198.     ; IN: BX = original ticks (for timeout)
  199.     ;     AX = time to wait
  200.     ;
  201.     ;OUT: CF = 1 if time expired
  202.     ────────────────────────────────────────────────────────────────────
  203. PROC CheckTime NEAR    
  204.     pusha
  205.     mov     [cs:CTMax],ax
  206.     mov     ah,0
  207.     int     1ah
  208.     cmp     bx,dx
  209.     jg      short @@Time1   ;check for wrap around
  210.  
  211.     sub     dx,bx
  212.     jmp     short @@Time2
  213.  
  214. @@Time1:
  215.     mov     ax,0ffffh
  216.     sub     ax,bx
  217.     add     dx,ax
  218.  
  219. @@Time2:
  220.     cmp     dx,[cs:CtMax]
  221.     ja      short @@TimeOut
  222.     clc     
  223.     jmp     short @@Exit
  224.  
  225. @@TimeOut:
  226.     stc
  227. @@Exit:
  228.     popa
  229.     ret
  230. ENDP
  231.     ────────────────────────────────────────────────────────────────────
  232.     ; sets BAUD rate
  233.     ────────────────────────────────────────────────────────────────────
  234. PROC SetBaudRate NEAR   
  235.     push    ax dx
  236.  
  237.     mov     dx,ComAddr+3
  238.     in      al,dx
  239.     or      al,10000000b
  240.     out     dx,al
  241.  
  242.     sub     dl,2
  243.     mov     al,BRDMSB       ;set the baud rates
  244.     out     dx,al
  245.  
  246.     dec     dl
  247.     mov     al,BRDLSB
  248.     out     dx,al
  249.  
  250.     add     dl,3
  251.     in      al,dx
  252.     and     al,01111111b    
  253.     out     dx,al
  254.  
  255.     pop     dx ax
  256.     ret
  257. ENDP
  258.  
  259.     ────────────────────────────────────────────────────────────────────
  260.     ; The following routine prints the ASCIIZ string pointed to by DS:SI
  261.     ────────────────────────────────────────────────────────────────────
  262. PROC PrintZ NEAR
  263.     push    ax dx si
  264.  
  265.     mov     ah,2
  266. @@PLoop:
  267.     mov     dl,[si]
  268.     inc     si
  269.     or      dl,dl
  270.     je      short @@Done
  271.     int     21h
  272.     jmp     short @@PLoop
  273.  
  274. @@Done:
  275.     pop     si dx ax
  276.     ret
  277. ENDP
  278.  
  279.     ────────────────────────────────────────────────────────────────────
  280.     ; Interrupt handler - process byte coming in on serial channel (COM)
  281.     ────────────────────────────────────────────────────────────────────
  282. PROC IntHandler FAR
  283.     push    ax dx ds es di
  284.  
  285.     mov     dx,ComAddr+4        ;point to modem control register
  286.     in      al,dx       
  287.     and     al,11111101b        ;turn off RTS
  288.     out     dx,al
  289.  
  290.     mov     ax,cs
  291.     mov     ds,ax
  292.     mov     es,[BuffSeg]
  293.     mov     di,[Head]
  294.     cld
  295.  
  296. @@Recieve:
  297.     mov     dx,ComAddr
  298.     in      al,dx
  299.     stosb
  300.     cmp     di,BuffSize
  301.     jne     @@NoWrap
  302.     xor     di,di
  303.  
  304. @@NoWrap:
  305.     mov     [Head],di
  306.  
  307.     mov     dx,Comaddr+2            ;is another byte ready??
  308.     in      al,dx
  309.     test    al,1        
  310.     jz      @@Recieve
  311.  
  312.     mov     al,20h
  313.     out     20h,al
  314.  
  315.     mov     dx,Comaddr+4        ;turn RTS back on
  316.     in      al,dx
  317.     or      al,00000010b
  318.     out     dx,al
  319.  
  320.     pop     di es ds dx ax
  321.     iret
  322. ENDP
  323. ────────────────────────────────────────────────────────────────────────────
  324. START:
  325.     mov     bx,ss
  326.     mov     ax,es
  327.     sub     bx,ax
  328.     mov     ax,sp
  329.     add     ax,15
  330.     shr     ax,4
  331.     add     bx,ax
  332.     mov     ah,4ah
  333.     int     21h     ;shrink down to minimum
  334.  
  335.     mov     ax,cs
  336.     mov     ds,ax
  337.  
  338.     mov     ah,48h
  339.     mov     bx,BuffSize/16
  340.     int     21h
  341.     jnc     @@MemOK
  342.  
  343.     mov     si,offset MSG_NoMem
  344.     call    PrintZ
  345.     jmp     @@AllDone
  346.  
  347. @@MemOk:
  348.     mov     [BuffSeg],ax
  349.     call    SetUpComPort
  350.  
  351.     mov     si,offset MSG_Exit
  352.     call    PrintZ
  353.  
  354. @@MainLoop:
  355.     mov     ah,11h
  356.     int     16h
  357.     jz      @@NoKey
  358.  
  359.     mov     ah,10h
  360.     int     16h
  361.     cmp     ah,134      ;f12 key?
  362.     je      @@AllDone
  363.  
  364.     cmp     ah,133      ;f11 key? (toggle local echo)
  365.     jne     @@Notoggle
  366.     xor     [LocalEcho],1
  367.  
  368. @@Notoggle:
  369.     cmp     [LocalEcho],0       ;is local echo on?
  370.     je      @@noEcho
  371.  
  372.     push    ax
  373.     mov     ah,2
  374.     mov     dl,al
  375.     int     21h
  376.     pop     ax
  377.  
  378. @@noEcho:
  379.     call    SendChar
  380.     jnc     @@NoKey
  381.  
  382.     mov     si,offset MSG_TimeOut
  383.     call    PrintZ
  384.  
  385. @@NoKey:
  386.     call    DisplayBuffer
  387.     jmp     @@MainLoop
  388.  
  389. @@AllDone:
  390.     call    TurnOffComPort
  391.     mov     es,[Buffseg]
  392.     mov     ah,49h
  393.     int     21h
  394.  
  395.     mov     ax,4c00h
  396.     int     21h
  397. END Start            
  398.  
  399.